home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
049a.dms
/
049a.adf
/
articles
/
chapter15.asc
< prev
next >
Wrap
Text File
|
1993-09-09
|
9KB
|
253 lines
@1The following article is from the F1 Licenceware title, Absolute Beginners
Guide To Amos, By Andy Pine. See F1 Products article for more info.
Also look in the drawer EXAMPLE_PROGRAMS for the source code to go with
this article.@2
The Absolute Beginners Guide To Amos
-------------------------------------
Chapter fifteen
---------------@1
Now I would like to show you an easy way to detect mouse selections.
There are quite a few ways to set up menus that use the mouse but as we
are trying to learn the basics I will show you the simplest way I could
think of. It`s not the best way but it is straight forward and neat.
If you have already looked at EXAMPLE15.Amos you will se how this system
works:
1) We first draw some boxes for our text onto the screen
2) We then detect if the user has pressed a mouse key
3) Act on the mouse click
4) If inside a box perform the related task.
5) If outside a box then goto 2)
That is a broad outline of the program I will now go through the program
line for line.
SCREEN OPEN 0,640,200,8,HIRES
-----------------------------
Open a custom screen, simply because it looks nice and gives more room for
text operations and the like.
CHANGE MOUSE 2: PAPER 6: CURS OFF: CLS 6
----------------------------------------
Set the mouse pointer to a cross hair and switch the text cursor off, set
text paper to the same as the background screen colour (6) a nice blue.
UNDER ON
--------
A new command but nice and straight forward. This simply sets underlined
text to ON, so any text PRINTed from now on will automatically be UNDERlined,
at least until Amos comes to an UNDER OFF statement.
CENTRE "Move the mouse pointer over a box and click left button"
----------------------------------------------------------------
Centralize the forthcoming string of text (This will be underlined as well)
Note: As we haven`t set the text cursor to any position yet in this program
this text will be on line 0.
UNDER OFF
---------
Now turn UNDERlining OFF.
RESERVE ZONE 4
--------------
We will want four menu boxes in this example so we have to reserve space for
them using RESERVE ZONE. Don`t worry why at this stage just remember that
the menus will not work without this command first.
LOCATE 20,10: PRINT BORDER$(ZONE$("BOX 1",1),1)
-----------------------------------------------
WE know what the LOCATE and PRINT do. The rest of the line is as follows,
BORDER$(ZONE$(
---------------
Is always the same (you can leave border$ out if you want)
"BOX 1"
-------
This is the text you wish to be displayed inside the menu box, in quotes.
,1),1)
------
The first number is the menu I.D for our use (1) and the second 1 is the type
of border pattern we want around the box, ranges are 1 to 16 try out some
different patterns in EXAMPLE15.Amo. If you don`t want borders around your
text then delete the first bracket and the ,1) at the end.
The next three lines are virtually the same except for the text and I.D
number.
KEE:
----
This is a label for GOTO to jump to. See last line of program.
WHILE MOUSE KEY=0: WEND
-----------------------
This excellent and useful little line continually loops until a mouse key is
pressed where upon the program continues. It is very similar to the WAIT KEY
command we have been using but instead uses any mouse button.
Make a note for use in your future programs. The WHILE WEND loop, as it is
known, will repeat anything inside the WHILE and WEND commands repeatedly
until a condition is met, in this case a mouse button click. WHILE can be
proceeded by as many commands as you need.
KK=MOUSE ZONE
-------------
Really we do not need this line. What it does is tells the variable KK to
hold the current zone number the mouse pointer is over. If the mouse is not
over any zone at all the value of kk (and mouse zone) will be zero.
We will see why it`s not totally necessary in a moment.
LOCATE 0,20
-----------
Set the text cursor to 0 across 20 down, ready for PRINTing to.
IF KK=1 THEN CENTRE "YOU SELECTED BOX 1"
----------------------------------------
We could also have used IF MOUSE ZONE=1 but KK is quicker and neater to use.
So if KK=1 (the zone the mouse pointer has been clicked over) THEN PRINT etc.
The following two lines are similar except for the text in the quotes.
IF KK=4 THEN CENTRE "YOU SELECTED EXIT": WAIT 50: EDIT
------------------------------------------------------
We have used box 4 as an exit to the program, WAIT enough time for the user
to read the message then goto EDIT mode.
GOTO KEE
--------
The mouse key was pressed but KK was not equal to 1,2,3 or 4 so no box was
clicked on (KK equal to 0) so we jump back to start checking all over again.
I won`t spend any more time on this as EXAMPLE15.Amos will make it all clear.
Spend a little time with this program and you could knock up some neat little
menus. How about a background picture with the boxes overlaid? Remember that
when you use a picture the palette will change the system colours.
By the way if you load a picture of a different size to a screen you have
previously opened then Amos will change the size of the screen accordingly
for you, so for example if you did this,
SCREEN OPEN 0,640,256,8,hires
Then you loaded a picture which was Lowres 320X200 then Amos would scrap
your hires screen for the dimensions of the newly loaded picture.
You can get round this by loading the picture into a spare screen and using
the SCREEN command to display it,
SCREEN OPEN 0,640,256,8,hires
SCREEN OPEN 1,320,200,16,lowres
LOAD IFF :picname",1
The picture will then be displayed on screen 1 and when you wish to use
screen 0 (your hires screen) you just use the command SCREEN 0.
The menu program was good as far as simplicity goes but using a similar
method with a few more commands we could make this menu system much more
flexible and neater take a look at EXAMPLE15_1.Amos it`s quite an improvement
don`t you think?
As there are only a few commands we haven`t covered in EXAMPLE15_1.Amos and
as it is highly REMmed I will just explain the new commands.
SET ZONE
-------
After using RESERVE ZONE we have to tell Amos exactly in coordinates where
the top left and bottom right corners of each of our selection boxes are.
In the prevoius example using ZONE$ Amos did this for us.
As the coordinates are hardware coordinates this is a pain so on this disk
in the EXTRAS drawer you will find a program I wrote years ago called
GETZONE.Amos It will allow you to load an IFF picture or ABK SPACKED picture
of any size you then click once on the top right corner of a menu box and
then the bottom right corner the hardware coordinates will then be displayed
for you to write down, press a mouse key and you can do your next menu and so
on.
The good thing about this new menu system we are going to use is you are not
limited to a box for your menu in fact it can be any rectangular shape or
size, within reason of course.
OK so we know our coordinates, we now need to let Amos know them too.
This is where SET ZONE comes in to it. In EXAMPLE15_1.Amos we have three
menu options so we need to set three zones 1 to 3 these will be the I.D
numbers for our menus throughout the program.
SET ZONE 1, The menu I.D
SET ZONE 1, 256,93 TO And coordinates of the top left edge of menu
SET ZONE 1, 256,93 TO 362,104 And the second set, bottom left coordinates
And that is it now just insert the rest of your coordinates like this,
SET ZONE 2,256,109 TO 362,109
etc.
Note: If like in the example program you are unpacking a screen then make
sure you unpack the screen BEFORE SETting ZONEs as they will be cleared.
There are two more commands we have not covered from EXAMPLE15_1.Amos
these are,
GOSUB
and
RETURN
These two commands are related, You GOSUB to a routine and then RETURN from
it when completed.
GOSUB is almost the same as GOTO but has one extra powerful feature the
RETURN part, here is an example,
GOSUB F1
PRINT "I`VE BEEN TO F1"
STOP
F1:
PRINT "I am now in a subroutine"
RETURN
The program goes to the part of the program labelled F1: and executes
commands until it reaches a RETURN instruction, and this is the good part,
the program then continues from the instruction immediately after the GOSUB
call. So what! You may say, what use is that? Well what if we wanted to
execute the same routine lots of times during a program we just call it with
GOSUB then continue executing from after the gosub as if nothing happened.
In Amos the GOSUB has taken a bit of a backseat because of a command called
PROCEDURE and we will be covering that subject very soon, but now you know
about GOTO and GOSUB, PROCEDURE will be a lot easier to understand.
For a good example of GOSUB check out Example15_1.Amos.
End of chapter fifteen.